package test.study.mybatis.client._8_binding.jdk;

import java.lang.reflect.Proxy;

public class MapperProxyFactoryV2<T> {

    private Class<T> clazz;

    public MapperProxyFactoryV2(Class<T> clazz) {
        this.clazz = clazz;
    }

    public T newInstance() {
        //加载器
        ClassLoader classLoader = clazz.getClassLoader();
        //被代理接口
        Class[] clazzArr = new Class[]{clazz};
        //拦截逻辑
        MapperProxyV2<T> mapperProxy = new MapperProxyV2<>(clazz);

        T t = (T) Proxy.newProxyInstance(classLoader, clazzArr, mapperProxy);
        return t;
    }
}
